import 'package:flutter/material.dart';
import 'package:local_coffee/components/c_row/custom_row.dart';
import 'package:local_coffee/components/icon.dart';
import 'package:local_coffee/components/rgba.dart';
import 'package:local_coffee/components/hex.dart';
import 'package:local_coffee/jsonserialize/user/data.dart';
import 'package:local_coffee/routes/index.dart';
import 'package:local_coffee/utils/global.dart';

class Mine extends StatefulWidget {
  
  static _MineState _mineState;

  getAppBar() => _mineState.createAppBar();

  Mine() {
    _mineState = _MineState();
  }

  _MineState createState() => _MineState();
}

class _MineState extends State<Mine> {
  
  AppBar createAppBar() {
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        color: RGBA.rgbaf8f8f8,
        child: Column(
          children: <Widget>[
            // 头部
            Container(
              alignment: Alignment.centerLeft,
              height: 180,
              color: RGBA.rgba64443c,
              padding: EdgeInsets.only(
                left: 20,
                right: 20,
                top: 44
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                    alignment: Alignment.centerRight,
                    margin: EdgeInsets.only(bottom: 20),
                    child: icon0xe61d(
                      color: RGBA.rgbaffffff09,
                      size: 24
                    ),
                  ),
                  buildUser()
                ],
              ),
            ),
            Container(
              color: HEX.hexfff,
              padding: EdgeInsets.symmetric(horizontal: 15),
              child: Column(
                children: <Widget>[
                  CustomRow(
                    height: 50,
                    padding: EdgeInsets.all(0),
                    leftChild: Container(
                      width: 30,
                      alignment: Alignment.centerLeft,
                      child: icon0xe6e0(
                        color: RGBA.rgbae4e4e4,
                        size: 14
                      ),
                    ),
                  ),
                  CustomRow(
                    height: 50,
                    padding: EdgeInsets.all(0),
                    leftChild: Container(
                      width: 30,
                      alignment: Alignment.centerLeft,
                      child: Container(
                        padding: EdgeInsets.only(bottom: 5),
                        child: icon0xe614(
                          color: RGBA.rgbadcdcdc,
                          size: 20
                        ),
                      ),
                    ),
                    centerChild: Text('咖啡钱包'),
                    rightChild: icon0xe60f(
                      color: RGBA.rgbae4e4e4, 
                      size: 14
                    ),
                  ),
                  CustomRow(
                    height: 50,
                    padding: EdgeInsets.all(0),
                    leftChild: Container(
                      width: 30,
                      alignment: Alignment.centerLeft,
                      child: Container(
                        child: icon0xe610(
                          color: RGBA.rgbadcdcdc,
                          size: 20
                        ),
                      ),
                    ),
                    centerChild: Text('优惠券'),
                    rightChild: icon0xe60f(
                      color: RGBA.rgbae4e4e4,
                      size: 14
                    ),
                  ),
                  CustomRow(
                    height: 50,
                    padding: EdgeInsets.all(0),
                    leftChild: Container(
                      width: 30,
                      alignment: Alignment.centerLeft,
                      child: Container(
                        child: icon0xe618(
                          color: RGBA.rgbadcdcdc,
                          size: 20
                        ),
                      ),
                    ),
                    centerChild: Text('兑换优惠'),
                    rightChild: icon0xe60f(
                      color: RGBA.rgbae4e4e4,
                      size: 14
                    ),
                  ),
                  CustomRow(
                    height: 50,
                    padding: EdgeInsets.all(0),
                    leftChild: Container(
                      width: 30,
                      alignment: Alignment.centerLeft,
                      child: Container(
                        child: icon0xe612(
                          color: RGBA.rgbadcdcdc,
                          size: 20
                        ),
                      ),
                    ),
                    centerChild: Text('发票管理'),
                    rightChild: icon0xe60f(
                      color: RGBA.rgbae4e4e4,
                      size: 14
                    ),
                  )
                ],
              ),
            ),
            CustomRow(
              height: 50,
              margin: EdgeInsets.only(top: 10),
              padding: EdgeInsets.symmetric(horizontal: 15),
              leftChild: Container(
                width: 30,
                alignment: Alignment.centerLeft,
                child: Container(
                  child: icon0xe6d9(
                    color: RGBA.rgbadcdcdc,
                    size: 20
                  ),
                ),
              ),
              centerChild: Text('发票反馈'),
              rightChild: icon0xe60f(
                color: RGBA.rgbae4e4e4,
                size: 14
              ),
              border: G.borderBottom(show: false),
            ),
            Container(
              margin: EdgeInsets.only(top: 10),
              padding: EdgeInsets.symmetric(horizontal: 15),
              child: Image.asset(
                P.mine2,
                fit: BoxFit.cover,
              ),
            )
          ],
        ),
      ),
    );
  }

  CustomRow buildUser() {
    UserData userData = G.user.data;

    return CustomRow(
      height: 55,
      color: Colors.transparent,
      border: G.borderBottom(show: false),
      padding: EdgeInsets.all(0),
      leftChild: ClipRRect(
        borderRadius: BorderRadius.circular(27),
        child: Image.asset(
          P.mine1,
          width: 55,
          height: 55,
          fit: BoxFit.cover,
        ),
      ),
      centerChild: Container(
        margin: EdgeInsets.only(left: 10),
        child: Text(
          userData == null ? '立即登录' : userData.nick,
          style: TextStyle(
            color: RGBA.rgbaffffff1,
            fontSize: 18
          ),
        ),
      ),
      rightChild: icon0xe60f(
        color: RGBA.rgbaffffff06,
        size: 14
      ),
      onPressed: () {
        if (userData == null) {
          G.pushNamed(N.loginMail);
        }
      },
    );
  }
}